package com.hd123.rumba.gwt.widget.client;

import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.PopupListener;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

public class ReconcileDialog extends DialogBox implements ClickListener {
  public static int BUTTON_IGNORE = 1;
  public static int BUTTON_RETRY = 2;
  public static int BUTTON_CANCEL = 4;
  int modalResult = 0;
  Label message;
  HorizontalPanel hp;
  Button ignoreButton;
  Button retryButton;
  Button cancelButton;

  public ReconcileDialog(PopupListener listener) {
    super(false, true);
    setText("请确认:");

    VerticalPanel vp = new VerticalPanel();
    vp.setSpacing(10);
    vp.add(message = new Label());

    hp = new HorizontalPanel();
    hp.setSpacing(10);
    hp.add(ignoreButton = new Button("忽略", this));
    ignoreButton.setWidth("50px");
    hp.add(retryButton = new Button("重试", this));
    retryButton.setWidth("50px");
    hp.add(cancelButton = new Button("取消", this));
    cancelButton.setWidth("50px");
    vp.add(hp);
    vp.setCellHorizontalAlignment(hp, VerticalPanel.ALIGN_CENTER);

    setWidget(vp);
    this.addPopupListener(listener);
  }

  public void show(String message) {
    this.modalResult = 0;
    this.message.setText(message);
    show();
    center();
  }

  public int getResult() {
    return modalResult;
  }

  public void onClick(Widget sender) {
    if (sender == ignoreButton)
      modalResult = BUTTON_IGNORE;
    else if (sender == retryButton)
      modalResult = BUTTON_RETRY;
    else if (sender == cancelButton)
      modalResult = BUTTON_CANCEL;
    hide();
  }
}
